<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />

<!-- CSSファイルの読み込み -->

<link rel="stylesheet" type="text/css" href="../css/reset.min.css" />
<link rel="stylesheet" type="text/css" href="../css/style.min.css" />
<link rel="stylesheet" type="text/css" href="../css/albumStyle.min.css" />
<script type="text/javascript" src="../js/jquery-1.10.1.min.js"></script>
<script src="../js/alert1.js" type="text/javascript"></script>
<script type="text/javascript">
	var check;
	function callConfirm(){
		check = confirm('削除してよろしいですか？');
		if(check){
			return true;
		}else{
			return false;
		}
	}
	$("document").ready(function(){
		var column = 3;
		var pCount = <?php print count($this->data);?>;
		var pTarget = $('#picture td');
		var xTarget = $('#remove td');
		var fCount = pTarget.length;
		var vCount = Math.ceil(pCount/column)-1;
		var buttonIndex=0;
		for(var i=0;i<fCount;i++){
			pTarget.eq(i).show();
			xTarget.eq(i).show();
			if(i==column-1) break;
		}
		$('#ltButton').bind('click',function(){
			buttonIndex--;
			if(buttonIndex<=0) {
				buttonIndex=0;
				$(this).attr("disabled", "disabled");
				$('#gtButton').removeAttr("disabled");
			}
			$('#gtButton').removeAttr("disabled");
			$('#picture td').hide();
			$('#remove td').hide();
			$('td.'+buttonIndex).show();
		});
		$('#gtButton').bind('click',function(){
			buttonIndex++;
			if(buttonIndex>=vCount) {
				buttonIndex=vCount;
				$(this).attr("disabled", "disabled");
				$('#ltButton').removeAttr("disabled");
			}
			$('#ltButton').removeAttr("disabled");
			$('#picture td').hide();
			$('#remove td').hide();
			$('td.'+buttonIndex).show();
		});
	});
</script>
<title>アルバム | ファン</title>
</head>
<body id="photoList">
	<?php require_once 'commonHeader.php';?>
	<!-- パンくずリスト -->
	<!-- ページに応じて各自書き換えること。また、hrefの中にファイル場所の記述も。 -->

	<ul id="bread" class="clear">

		<li><a href="userController.php?request=showIndex" id="home">ホーム</a>&gt;</li>
		<li><a href="albumController.php?request=showAlbumList">アルバム&gt;</a></li>
		<li><a href="#">アルバムタイトル</a></li>

	</ul>
	<!-- contents -->
	<article id="contents" class="clear">
		<!-- アルバム一覧 -->
		<section id="contentsArea">
			<h2 class="contentsTitle">
				<?php print $_SESSION['ATitle']; ?>
			</h2>
			<hr>
			<p><?php print $_SESSION['AContent']; ?></p>
			<div class="clear">
				<p class="editButton">
					<a href="albumController.php?request=showAlbumEdit&AIndex=<?php print $_SESSION['AIndex'];?>">編集</a>
				</p>
				
				<form name="form1" action="albumController.php" method="POST" 
				enctype="multipart/form-data" class="fileUp" onsubmit="submitButton.disabled = true; return true;">
					<input type="hidden" name="request" value="insertPhoto" />
					<input type="hidden" name="AIndex" value="<?php print $_SESSION['AIndex']; ?>" />
					<input type="file" name="upfile" />
					<input id="submitButton" type="submit" onclick="return jfk()" value="アップロード" class="submit" />
				</form>

			</div>

			<!-- 写真一覧 -->
			<section>
				<table id="photoTable">
					<tr>
						<th colspan="5">写真一覧</th>
					</tr>
					<?php
					$column=3;
					$rnd = md5(rand());
					$_SESSION['token'] = $rnd;
					$count = count($this->data);
					print "<tr id='picture'>";
					for ($i=0;$i<$count;$i++) {
						$id = floor($i/$column);
						print "<td class='{$id}' style='display:none;'>";
						print "<img src='../".$this->data[$i]['PPath']."' width=200em height=150em />";
						print "</td>";
					}
					print "</tr><tr id='remove'>";
					for ($i=0;$i<$count;$i++) {
						$id = floor($i/$column);
						if ($_SESSION['userId']!=$this->data[$i]['userId']){
							print "<td class='{$id}' style='display:none;'></td>";
							continue;
						}
						print "<td class='{$id}' style='display:none;'><p class='delButton'>";
						print "<a href='albumController.php?
								request=deletePhoto&AIndex={$this->data[$i]['AIndex']}
								&PIndex={$this->data[$i]['PIndex']}&token={$rnd}'.
								onclick='return callConfirm()'>削除</a></p></td>";
					}
					print "</tr>";
					?>

				</table>
				<div style="margin-left: 45%">
					<button id="ltButton" disabled="disabled">&lt;&lt;</button>
					<button id="gtButton" <?php if(count($this->data)<=3) print "disabled='disabled'"?> >&gt;&gt;</button>
				</div>
			</section>

		</section>


	</article>

	<?php require_once 'commonFooter.php';?>